package com.example.student.controller;
import com.example.student.pojo.Admin;
import com.example.student.pojo.Result;
import com.example.student.service.LoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 34082
 * 登录的操作
 */
@Slf4j
@RestController

public class LoginController {

    private LoginService loginService;

    @Autowired
    public void setLoginService(LoginService loginService) {
        this.loginService = loginService;
    }

    @PostMapping("/login")
    public Result login(@RequestParam String username, @RequestParam String password) {
        Admin admin = loginService.login(username, password);
        if (admin != null) {
            return Result.success();
        } else {return Result.error("用户名或密码错误");}
    }


}